import request from '@/utils/request'
//6、给用户分配角色
export const AssignRoles = (userId, roleIds) => {
  return request({
    url: `/admin/system/userRole/assignRoles`,
    method: 'PUT',
    // roleIds.join()  将数组中多个值 以逗号连接成字符串
    // [1,2,3]    ==>  roleIds:1,2,3
    params: { userId, roleIds: roleIds.join() },
  })
}

//1、条件查询角色分页
//访问的后端接口： 需要请求头携带token(请求拦截器中已经配置过)
//   请求参数携带keyword、路径携带pageNum+pageSize
export const GetSysUserPage = (searchObj, pageNum, pageSize) => {
  return request({
    url: `/admin/system/user/page/${pageNum}/${pageSize}`,
    method: 'get',
    // {keyword:xx , createTimeStart:2023-05-01}
    params: searchObj,
  })
}
//2、新增
export const SaveSysUser = sysUser => {
  return request({
    url: `/admin/system/user`,
    method: 'post',
    data: sysUser,
  })
}
//3、删除
export const DelById = id => {
  return request({
    url: `/admin/system/user/${id}`,
    method: 'delete',
  })
}
//4、根据id查询
export const GetById = id => {
  return request({
    url: `/admin/system/user/${id}`,
    method: 'get',
  })
}
//5、更新
export const UpdateById = sysUser => {
  return request({
    url: `/admin/system/user`,
    method: 'put',
    data: sysUser,
  })
}
